--[[
Project: HunterRP
File: commands.lua
Author: Sebihunter
]]--

function giveMoney(ply, command, args)
	if args == "" then return "" end

	if not tonumber(args) then
		return ""
	end
	
	local trace = ply:GetEyeTrace()
	
	if ValidEntity(trace.Entity) and trace.Entity:IsPlayer() and trace.Entity:GetPos():Distance(ply:GetPos()) < 250 then
		local amount = math.floor(tonumber(args))
		
		if amount < 1 then
			ply:PrintMessage(HUD_PRINTTALK, "Invalid money ammount!")	
			return
		end
		
		if amount > ply:GetNWInt("money") then
			ply:PrintMessage(HUD_PRINTTALK, "You do not have enough money!")	
			return
		end		
		
		ply:PrintMessage(HUD_PRINTTALK, "You gave "..ammount.."$ to "..trace.Entity:Nick()".")
		trace.Entity:PrintMessage(HUD_PRINTTALK, "You recieved "..ammount.."$ from "..ply:Nick()".")
	end
end
concommand.Add("givemoney", giveMoney)